Last updated: 2019-12-04

Checks: 4 2

Knit directory: ~/Research-Local/RNAseq-Local/

This reproducible R Markdown analysis was created with workflowr (version 1.4.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(12345) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/Users/parajago/Research-Local/RNAseq-Local/Inputs/NigerianTCGA_quants-proteincoding Inputs/NigerianTCGA_quants-proteincoding

Tracking code development and connecting the code version to the results is critical for reproducibility. To start using Git, open the Terminal and type git init in your project directory.


This project is not being versioned with Git. To obtain the full reproducibility benefits of using workflowr, please see ?wflow_start.


#Translation from HTSeq raw counts -> Count Matrix I have 84 TCGA patients with whole-genome sequencing data and RNAseq data as well as 96 Nigerian patients with RNA-seq data. Raw counts were initially processed using HTSeq, so HTSeq data is being formatted for use with DESeq2 and limma-voom.

FOLDER <- "/Users/parajago/Research-Local/RNAseq-Local/Inputs/NigerianTCGA_quants-proteincoding"
sampleFiles <- grep("htseq.counts",list.files(FOLDER),value=TRUE)

#Differential gene expression setup based on race (b/w/other)
sampleConditionrace <- sampleFiles
countVar2=1
for (sample in sampleConditionrace){
  if (stri_detect_fixed(sample,"LIB")==TRUE){
    sampleConditionrace[countVar2] <- "Nigerian"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"black")==TRUE){
    sampleConditionrace[countVar2] <- "TCGA_black"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"white")==TRUE){
    sampleConditionrace[countVar2] <- "TCGA_white"
    countVar2=countVar2+1
  } else{
    sampleConditionrace[countVar2] <- "TCGA_other"
    countVar2=countVar2+1
  }
}

#Condition based on PAM50 subtype 
sampleConditionPAM50 <- sampleFiles
countVar2=1
for (sample in sampleConditionPAM50){
  if (stri_detect_fixed(sample,"Her2")==TRUE){
    sampleConditionPAM50[countVar2] <- "Her2"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"Basal")==TRUE){
    sampleConditionPAM50[countVar2] <- "Basal"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"LumA")==TRUE){
    sampleConditionPAM50[countVar2] <- "LumA"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"LumB")==TRUE){
    sampleConditionPAM50[countVar2] <- "LumB"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"PAMNL")==TRUE){
    sampleConditionPAM50[countVar2] <- "Normal"
    countVar2=countVar2+1
  } else{
    sampleConditionPAM50[countVar2] <- "PAM_other"
    countVar2=countVar2+1
  }
}

#Condition based on batch (relevant to the Nigerian patients only; no difference in batch for the TCGA patients)
batchval <- sampleFiles
countVar2=1
for (sample in batchval){
  if (stri_detect_fixed(sample,"batch1")==TRUE){
    batchval[countVar2] <- "batch1"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch23")==TRUE){
    batchval[countVar2] <- "batch23"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch4")==TRUE){
    batchval[countVar2] <- "batch4"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch5")==TRUE){
    batchval[countVar2] <- "batch5"
    countVar2=countVar2+1
  } else{
    batchval[countVar2] <- "batchT"
    countVar2=countVar2+1
  }
}

table(sampleConditionrace, sampleConditionPAM50)
                   sampleConditionPAM50
sampleConditionrace Basal Her2 LumA LumB Normal PAM_other
         Nigerian      41   27   14   11      3         0
         TCGA_black    23    0    4    4      0         0
         TCGA_other     0    0    0    0      0        14
         TCGA_white    17    5    8    9      0         0
sampleTable <- data.frame(sampleName=gsub(".htseq.counts","",sampleFiles),
                          fileName=sampleFiles,
                          condition1=sampleConditionrace,
                          condition2=sampleConditionPAM50,
                          batch=batchval)

sampleTable$sampleCondition <- paste(sampleTable$condition1, sampleTable$condition2, sep=".")

ddsHTSeqMF <- DESeqDataSetFromHTSeqCount(sampleTable=sampleTable,
                                       directory=FOLDER,
                                       design=~sampleCondition)

ddsHTSeqMF <- ddsHTSeqMF[rowSums(counts(ddsHTSeqMF)) > 0, ] #Pre-filtering the dataset by removing the rows without any information about gene expression -> this removes 603 genes

#Quantile normalization Please refer to: https://parajago.github.io/TCGA-Nigerian-RNAseq/NigerianTCGArawcountsDeSeq2-pc2.html regarding comparison between the Nigerian and TCGA data sets and why quantile normalization under the limma-voom approach was chosen for primary differential expression analysis.

##Data visualization

countmatrix <- assay(ddsHTSeqMF) #Raw counts organized into matrix format from individual files
countmatrix2 <- log2(countmatrix + 1) #Basic transformation of the count data 

plot(density(countmatrix2[,1]),lwd=3,ylim=c(0,.30), main="Density of counts with log2[count]+1 transformation ONLY") 
for(i in 1:180){lines(density(countmatrix2[,i]),lwd=3)} #This demonstrates that there is a difference in distributions between the Nigerian and TCGA data with basic log transformation normalization 

norm_countmatrix <- as.matrix(countmatrix2) 
norm_countmatrix = normalize.quantiles(norm_countmatrix)
plot(density(norm_countmatrix[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization")
for(i in 1:180){lines(density(norm_countmatrix[,i]),lwd=3)} #This demonstrates the effect of comparative quantile normalization

colnames (norm_countmatrix) <- colnames (countmatrix2)
rownames (norm_countmatrix) <- rownames (countmatrix2)

norm_countmatrix <- as.data.frame(norm_countmatrix)
countmatrixNigerian <- dplyr::select(norm_countmatrix, contains("LIB"))
plot(density(countmatrixNigerian[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization - Nigerian")
for(i in 1:96){lines(density(countmatrixNigerian[,i]),lwd=3)} #This demonstrates the result of the normalized Nigerian counts separately

tcgacolnames <- colnames(countmatrix)
tcgacolnames <- setdiff(tcgacolnames, colnames(countmatrixNigerian))
countmatrixTCGA <- norm_countmatrix[ , tcgacolnames]
plot(density(countmatrixTCGA[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization - TCGA")
for(i in 1:84){
  lines(density(countmatrixTCGA[,i]),lwd=3);
#  print(colnames(countmatrix)[i])
#  invisible(readline(prompt=i))
  } #This demonstrates the result of the normalized TCGA counts separately

norm_countmatrix <- as.data.frame(norm_countmatrix)
t_norm_countmatrix <- t(norm_countmatrix)

t_norm_countmatrix <- cbind (t_norm_countmatrix, sampleTable) #This binds the characteristics of the original patients to the quantile normalized counts. CBinding was checked to make sure that patients were correctly aligned to characteristics. 

quant.pca <- prcomp(t_norm_countmatrix[,1:19724])
autoplot(quant.pca, data=t_norm_countmatrix, colour='sampleCondition', shape='condition1', main="PCA of quantile normalization results prior to DE analysis")

In the raw data with log transformation only, we are able to see that there are two peaks corresponding to the two datasets (Nigerian and TCGA). The quantile normalization demonstrates a PCA that has similar clustering. Only ~20% of the distribution of the data set is explained by the PCA1, 2 of the variables.

#Distribution of counts across groups

countmatrixNigerian.test <- countmatrixNigerian
Nigeriancounts <- as.data.frame(rowSums(countmatrixNigerian.test))
names(Nigeriancounts) <- c("sum")
Nigeriancounts$mean <- rowMeans(countmatrixNigerian.test)
Nigeriancounts$tfx <- log(Nigeriancounts$mean)+1
Nigeriancounts$gene <- rownames(Nigeriancounts)

countmatrixTCGA.test <- countmatrixTCGA
TCGAcounts <- as.data.frame(rowSums(countmatrixTCGA.test))
names(TCGAcounts) <- c("sum")
TCGAcounts$mean <- rowMeans(countmatrixTCGA.test)
TCGAcounts$tfx <- log(TCGAcounts$mean)+1
TCGAcounts$gene <- rownames(TCGAcounts)

ggplot(data=TCGAcounts, aes(tfx)) + 
     geom_histogram()

ggplot(data=Nigeriancounts, aes(tfx)) + 
     geom_histogram()

jointcounts <- merge(Nigeriancounts,TCGAcounts, by="gene")
corr <- cor.test(x=jointcounts$mean.x, y=jointcounts$mean.y, method = 'spearman')

#Differential expression setup

annotation <- as.data.frame(row.names(countmatrix))
colnames(annotation) <- c("GeneID")
annotation$temp <- gsub("[.].+", "", annotation[,1])

annotation$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

annotation$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

annotation$chr <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SEQNAME",
                     keytype="GENEID",           
                     multiVals="first")

annotation$locstart <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="GENESEQSTART",
                     keytype="GENEID",
                     multiVals="first")

annotation$locend <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="GENESEQEND",
                     keytype="GENEID",
                     multiVals="first")
annotation$temp <- NULL

design <- t_norm_countmatrix
design <- design %>% dplyr::select(sampleCondition)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - Basal

designNvsW <- design
designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition=="TCGA_white.Basal", 0, as.character(designNvsW$sampleCondition))
designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition=="Nigerian.Basal", 1, as.character(designNvsW$sampleCondition))

designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition==0 | designNvsW$sampleCondition==1, designNvsW$sampleCondition, NA)

designNvsW <- designNvsW %>% subset(is.na(sampleCondition)==FALSE)

designNvsW$TCGA_white.Basal <- ifelse (designNvsW$sampleCondition==0, 1, 0)
designNvsW$Nigerian.Basal <- ifelse (designNvsW$sampleCondition==1, 1, 0)

designNvsW$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsW$TCGA_white.Basal+designNvsW$Nigerian.Basal)

quantids <- rownames(designNvsW)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14785    58
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsW,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.Basal-Nigerian.Basal, levels=colnames(designNvsW))

fit <- lmFit(v, designNvsW)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.Basal - Nigerian.Basal
Down                                2342
NotSig                              9115
Up                                  3320
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between basal breast cancers in Nigerian and TCGA white patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between basal \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,50)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between basal \nbreast cancers in Nigerian and TCGA white breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_white-Nigerian-Basal-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA Black - Basal

designNvsB <- design
designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition=="TCGA_black.Basal", 0, as.character(designNvsB$sampleCondition))
designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition=="Nigerian.Basal", 1, as.character(designNvsB$sampleCondition))

designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition==0 | designNvsB$sampleCondition==1, designNvsB$sampleCondition, NA)

designNvsB <- designNvsB %>% subset(is.na(sampleCondition)==FALSE)

designNvsB$TCGA_black.Basal <- ifelse (designNvsB$sampleCondition==0, 1, 0)
designNvsB$Nigerian.Basal <- ifelse (designNvsB$sampleCondition==1, 1, 0)

designNvsB$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsB$TCGA_black.Basal+designNvsB$Nigerian.Basal)

quantids <- rownames(designNvsB)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14864    64
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsB,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_black.Basal-Nigerian.Basal, levels=colnames(designNvsB))

fit <- lmFit(v, designNvsB)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_black.Basal - Nigerian.Basal
Down                                2566
NotSig                              9013
Up                                  3277
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between TNBC breast cancers in Nigerian and TCGA black patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between Basal \nbreast cancers in Nigerian and TCGA black breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,50)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between basal \nbreast cancers in Nigerian and TCGA black breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_black-Nigerian-Basal-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

mm <- model.matrix(~0+designNvsW$TCGA_white.Basal+designNvsW$Nigerian.Basal)

quantids <- rownames(designNvsW)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14785    58
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsW,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.Basal-Nigerian.Basal, levels=colnames(designNvsW))

fit <- lmFit(v, designNvsW)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.Basal - Nigerian.Basal
Down                                2342
NotSig                              9115
Up                                  3320
df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = p.adjust(fit$p.value[,1], method='fdr'),
                       anno = fit$genes)

pathway.Nigerian.TCGAwhite.Basal <- as.data.frame(df_limma)

pathway.Nigerian.TCGAwhite.Basal$foldChange <- NA
row.pos <- which(! is.na(pathway.Nigerian.TCGAwhite.Basal$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.Basal$log2FoldChange >= 0)
row.neg <- which(! is.na(pathway.Nigerian.TCGAwhite.Basal$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.Basal$log2FoldChange < 0)
pathway.Nigerian.TCGAwhite.Basal$foldChange[row.pos] <- 2^pathway.Nigerian.TCGAwhite.Basal$log2FoldChange[row.pos]
pathway.Nigerian.TCGAwhite.Basal$foldChange[row.neg] <- -2^((-1) * pathway.Nigerian.TCGAwhite.Basal$log2FoldChange[row.neg])

pathway.Nigerian.TCGAwhite.Basal$log2FoldChange <- NULL
pathway.Nigerian.TCGAwhite.Basal$ENSEMBL <- pathway.Nigerian.TCGAwhite.Basal$anno$GeneID
pathway.Nigerian.TCGAwhite.Basal$SYMBOL <- pathway.Nigerian.TCGAwhite.Basal$anno$symbol

pathway.Nigerian.TCGAwhite.Basal$anno$GeneID <- NULL
pathway.Nigerian.TCGAwhite.Basal$anno$symbol <- NULL

pathway.Nigerian.TCGAwhite.Basal.flt <- pathway.Nigerian.TCGAwhite.Basal %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

genes.all <- pathway.Nigerian.TCGAwhite.Basal
genes.sig <- pathway.Nigerian.TCGAwhite.Basal.flt

genes.all$ENSEMBL <- gsub('[.]\\d+', '', genes.all$ENSEMBL, perl = TRUE)
genes.sig$ENSEMBL <- gsub('[.]\\d+', '', genes.sig$ENSEMBL, perl = TRUE)

genes.all.anno <- bitr(geneID   =  genes.all$ENSEMBL, 
                      fromType = 'GENEID', 
                      toType   = c('ENTREZID', 'SYMBOL'), 
                      OrgDb    = 'EnsDb.Hsapiens.v75', 
                      drop     = TRUE)

genes.all.anno <- genes.all.anno[which(!duplicated(genes.all.anno$ENTREZID)), ]
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.all.anno$ENSEMBL <- genes.all.anno$GENEID
genes.all.anno$GENEID <- NULL

genes.all.anno <- merge(genes.all.anno, genes.all, by = 'ENSEMBL')
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.sig.anno <- genes.all.anno[genes.all.anno$ENSEMBL %in% 
                                genes.sig$ENSEMBL,]

gene.list <- genes.all.anno$foldChange
names(gene.list) <- genes.all.anno$ENTREZID
gene.list <- sort(gene.list, decreasing = TRUE)

ego <- enrichGO(gene          = genes.sig.anno$ENTREZID,
                universe      = as.character(genes.all.anno$ENTREZID),
                OrgDb         = 'org.Hs.eg.db',
                ont           = "BP",
                pAdjustMethod = "fdr",
                pvalueCutoff  = 0.05,
                readable      = TRUE)

as.data.frame(ego)
save(ego, file="GO-Nigerian-TCGAwhite-Basal.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.RData")
write.csv(ego, file="GO-Nigerian-TCGAwhite-Basal.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.csv")

options(jupyter.plot_mimetypes = "image/svg+xml") 
options(repr.plot.width = 10, repr.plot.height = 5)

egokegg <- ego
for(i in 1:5) { 
  egokegg <- dropGO(egokegg, level = i)
}

p1 <- barplot(egokegg)
p2 <- dotplot(egokegg)

plot(p1)

plot(p2)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - HER2 (no TCGA Black HER2+ patients)

designNvsWHER2 <- design
designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition=="TCGA_white.Her2", 0, as.character(designNvsWHER2$sampleCondition))
designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition=="Nigerian.Her2", 1, as.character(designNvsWHER2$sampleCondition))

designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition==0 | designNvsWHER2$sampleCondition==1, designNvsWHER2$sampleCondition, NA)

designNvsWHER2 <- designNvsWHER2 %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHER2$TCGA_white.Her2 <- ifelse (designNvsWHER2$sampleCondition==0, 1, 0)
designNvsWHER2$Nigerian.Her2 <- ifelse (designNvsWHER2$sampleCondition==1, 1, 0)

designNvsWHER2$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHER2$TCGA_white.Her2+designNvsWHER2$Nigerian.Her2)

quantids <- rownames(designNvsWHER2)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13869    32
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsWHER2,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.Her2-Nigerian.Her2, levels=colnames(designNvsWHER2))

fit <- lmFit(v, designNvsWHER2)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.Her2 - Nigerian.Her2
Down                               316
NotSig                           12900
Up                                 645
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between Her2+ breast cancers in Nigerian and TCGA white patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between Her2+ \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,20)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between Her2 \nbreast cancers in Nigerian and TCGA white breast cancer patients")

write.csv(df_limmaprint, file = "TCGAwhite-Nigerian-Her2.woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

mm <- model.matrix(~0+designNvsWHER2$TCGA_white.Her2+designNvsWHER2$Nigerian.Her2)

quantids <- rownames(designNvsWHER2)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13869    32
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsWHER2,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.Her2-Nigerian.Her2, levels=colnames(designNvsWHER2))

fit <- lmFit(v, designNvsWHER2)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.Her2 - Nigerian.Her2
Down                               316
NotSig                           12900
Up                                 645
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

pathway.Nigerian.TCGAwhite.Her2 <- as.data.frame(df_limma)

pathway.Nigerian.TCGAwhite.Her2$foldChange <- NA
row.pos <- which(! is.na(pathway.Nigerian.TCGAwhite.Her2$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.Her2$log2FoldChange >= 0)
row.neg <- which(! is.na(pathway.Nigerian.TCGAwhite.Her2$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.Her2$log2FoldChange < 0)
pathway.Nigerian.TCGAwhite.Her2$foldChange[row.pos] <- 2^pathway.Nigerian.TCGAwhite.Her2$log2FoldChange[row.pos]
pathway.Nigerian.TCGAwhite.Her2$foldChange[row.neg] <- -2^((-1) * pathway.Nigerian.TCGAwhite.Her2$log2FoldChange[row.neg])

pathway.Nigerian.TCGAwhite.Her2$log2FoldChange <- NULL
pathway.Nigerian.TCGAwhite.Her2$ENSEMBL <- pathway.Nigerian.TCGAwhite.Her2$anno$GeneID
pathway.Nigerian.TCGAwhite.Her2$SYMBOL <- pathway.Nigerian.TCGAwhite.Her2$anno$symbol

pathway.Nigerian.TCGAwhite.Her2$anno$GeneID <- NULL
pathway.Nigerian.TCGAwhite.Her2$anno$symbol <- NULL

pathway.Nigerian.TCGAwhite.Her2.flt <- pathway.Nigerian.TCGAwhite.Her2 %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

genes.all <- pathway.Nigerian.TCGAwhite.Her2
genes.sig <- pathway.Nigerian.TCGAwhite.Her2.flt

genes.all$ENSEMBL <- gsub('[.]\\d+', '', genes.all$ENSEMBL, perl = TRUE)
genes.sig$ENSEMBL <- gsub('[.]\\d+', '', genes.sig$ENSEMBL, perl = TRUE)

genes.all.anno <- bitr(geneID   =  genes.all$ENSEMBL, 
                      fromType = 'GENEID', 
                      toType   = c('ENTREZID', 'SYMBOL'), 
                      OrgDb    = 'EnsDb.Hsapiens.v75', 
                      drop     = TRUE)

genes.all.anno <- genes.all.anno[which(!duplicated(genes.all.anno$ENTREZID)), ]
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.all.anno$ENSEMBL <- genes.all.anno$GENEID
genes.all.anno$GENEID <- NULL

genes.all.anno <- merge(genes.all.anno, genes.all, by = 'ENSEMBL')
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.sig.anno <- genes.all.anno[genes.all.anno$ENSEMBL %in% 
                                genes.sig$ENSEMBL,]

gene.list <- genes.all.anno$foldChange
names(gene.list) <- genes.all.anno$ENTREZID
gene.list <- sort(gene.list, decreasing = TRUE)

ego <- enrichGO(gene          = genes.sig.anno$ENTREZID,
                universe      = as.character(genes.all.anno$ENTREZID),
                OrgDb         = 'org.Hs.eg.db',
                ont           = "BP",
                pAdjustMethod = "fdr",
                pvalueCutoff  = 0.05,
                readable      = TRUE)

as.data.frame(ego)
save(ego, file="GO-Nigerian-TCGAwhite-Her2.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.RData")
write.csv(ego, file="GO-Nigerian-TCGAwhite-Her2.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.csv")

options(jupyter.plot_mimetypes = "image/svg+xml") 
options(repr.plot.width = 10, repr.plot.height = 5)

egokegg <- ego
for(i in 1:5) { 
  egokegg <- dropGO(egokegg, level = i)
}

p1 <- barplot(egokegg)
p2 <- dotplot(egokegg)

plot(p1)

plot(p2)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - LumA

designNvsWHR <- design
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="TCGA_white.LumA", 0, as.character(designNvsWHR$sampleCondition))
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="Nigerian.LumA", 1, as.character(designNvsWHR$sampleCondition))

designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition==0 | designNvsWHR$sampleCondition==1, designNvsWHR$sampleCondition, NA)

designNvsWHR <- designNvsWHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHR$TCGA_white.LumA <- ifelse (designNvsWHR$sampleCondition==0, 1, 0)
designNvsWHR$Nigerian.LumA <- ifelse (designNvsWHR$sampleCondition==1, 1, 0)

designNvsWHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHR$TCGA_white.LumA+designNvsWHR$Nigerian.LumA)

quantids <- rownames(designNvsWHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13663    22
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsWHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.LumA-Nigerian.LumA, levels=colnames(designNvsWHR))

fit <- lmFit(v, designNvsWHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.LumA - Nigerian.LumA
Down                              1090
NotSig                           10927
Up                                1638
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between LumA breast cancers in Nigerian and TCGA white patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between LumA \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,20)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between LumA \nbreast cancers in Nigerian and TCGA white breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_white-Nigerian-LumA-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA Black - LumA

designNvsBHR <- design
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="TCGA_black.LumA", 0, as.character(designNvsBHR$sampleCondition))
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="Nigerian.LumA", 1, as.character(designNvsBHR$sampleCondition))

designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition==0 | designNvsBHR$sampleCondition==1, designNvsBHR$sampleCondition, NA)

designNvsBHR <- designNvsBHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsBHR$TCGA_black.LumA <- ifelse (designNvsBHR$sampleCondition==0, 1, 0)
designNvsBHR$Nigerian.LumA <- ifelse (designNvsBHR$sampleCondition==1, 1, 0)

designNvsBHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsBHR$TCGA_black.LumA+designNvsBHR$Nigerian.LumA)

quantids <- rownames(designNvsBHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13530    18
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsBHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_black.LumA-Nigerian.LumA, levels=colnames(designNvsBHR))

fit <- lmFit(v, designNvsBHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_black.LumA - Nigerian.LumA
Down                               218
NotSig                           13043
Up                                 261
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between LumA breast cancers in Nigerian and TCGA black patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between LumA \nbreast cancers in Nigerian and TCGA black breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,20)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between LumA \nbreast cancers in Nigerian and TCGA white breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_black-Nigerian-LumA-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

designNvsWHR <- design
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="TCGA_white.LumA", 0, as.character(designNvsWHR$sampleCondition))
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="Nigerian.LumA", 1, as.character(designNvsWHR$sampleCondition))

designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition==0 | designNvsWHR$sampleCondition==1, designNvsWHR$sampleCondition, NA)

designNvsWHR <- designNvsWHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHR$TCGA_white.LumA <- ifelse (designNvsWHR$sampleCondition==0, 1, 0)
designNvsWHR$Nigerian.LumA <- ifelse (designNvsWHR$sampleCondition==1, 1, 0)

designNvsWHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHR$TCGA_white.LumA+designNvsWHR$Nigerian.LumA)

quantids <- rownames(designNvsWHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13663    22
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]


v=voom(d,designNvsWHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.LumA-Nigerian.LumA, levels=colnames(designNvsWHR))

fit <- lmFit(v, designNvsWHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.LumA - Nigerian.LumA
Down                              1090
NotSig                           10927
Up                                1638
df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = p.adjust(fit$p.value[,1], method='fdr'),
                       anno = fit$genes)

pathway.Nigerian.TCGAwhite.LumA <- as.data.frame(df_limma)

pathway.Nigerian.TCGAwhite.LumA$foldChange <- NA
row.pos <- which(! is.na(pathway.Nigerian.TCGAwhite.LumA$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.LumA$log2FoldChange >= 0)
row.neg <- which(! is.na(pathway.Nigerian.TCGAwhite.LumA$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.LumA$log2FoldChange < 0)
pathway.Nigerian.TCGAwhite.LumA$foldChange[row.pos] <- 2^pathway.Nigerian.TCGAwhite.LumA$log2FoldChange[row.pos]
pathway.Nigerian.TCGAwhite.LumA$foldChange[row.neg] <- -2^((-1) * pathway.Nigerian.TCGAwhite.LumA$log2FoldChange[row.neg])

pathway.Nigerian.TCGAwhite.LumA$log2FoldChange <- NULL
pathway.Nigerian.TCGAwhite.LumA$ENSEMBL <- pathway.Nigerian.TCGAwhite.LumA$anno$GeneID
pathway.Nigerian.TCGAwhite.LumA$SYMBOL <- pathway.Nigerian.TCGAwhite.LumA$anno$symbol

pathway.Nigerian.TCGAwhite.LumA$anno$GeneID <- NULL
pathway.Nigerian.TCGAwhite.LumA$anno$symbol <- NULL

pathway.Nigerian.TCGAwhite.LumA.flt <- pathway.Nigerian.TCGAwhite.LumA %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

genes.all <- pathway.Nigerian.TCGAwhite.LumA
genes.sig <- pathway.Nigerian.TCGAwhite.LumA.flt 

genes.all$ENSEMBL <- gsub('[.]\\d+', '', genes.all$ENSEMBL, perl = TRUE)
genes.sig$ENSEMBL <- gsub('[.]\\d+', '', genes.sig$ENSEMBL, perl = TRUE)

genes.all.anno <- bitr(geneID   =  genes.all$ENSEMBL, 
                      fromType = 'GENEID', 
                      toType   = c('ENTREZID', 'SYMBOL'), 
                      OrgDb    = 'EnsDb.Hsapiens.v75', 
                      drop     = TRUE)

genes.all.anno <- genes.all.anno[which(!duplicated(genes.all.anno$ENTREZID)), ]
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.all.anno$ENSEMBL <- genes.all.anno$GENEID
genes.all.anno$GENEID <- NULL

genes.all.anno <- merge(genes.all.anno, genes.all, by = 'ENSEMBL')
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.sig.anno <- genes.all.anno[genes.all.anno$ENSEMBL %in% 
                                genes.sig$ENSEMBL,]

gene.list <- genes.all.anno$foldChange
names(gene.list) <- genes.all.anno$ENTREZID
gene.list <- sort(gene.list, decreasing = TRUE)

ego <- enrichGO(gene          = genes.sig.anno$ENTREZID,
                universe      = as.character(genes.all.anno$ENTREZID),
                OrgDb         = 'org.Hs.eg.db',
                ont           = "BP",
                pAdjustMethod = "fdr",
                pvalueCutoff  = 0.05,
                readable      = TRUE)

as.data.frame(ego)
save(ego, file="GO-Nigerian-TCGAwhite-LumA.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.RData")
write.csv(ego, file="GO-Nigerian-TCGAwhite-LumA.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.csv")

options(jupyter.plot_mimetypes = "image/svg+xml") 
options(repr.plot.width = 10, repr.plot.height = 5)

egokegg <- ego
for(i in 1:5) { 
  egokegg <- dropGO(egokegg, level = i)
}

p1 <- barplot(egokegg)
p2 <- dotplot(egokegg)

plot(p1)

plot(p2)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - LumB

designNvsWHR <- design
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="TCGA_white.LumB", 0, as.character(designNvsWHR$sampleCondition))
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="Nigerian.LumB", 1, as.character(designNvsWHR$sampleCondition))

designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition==0 | designNvsWHR$sampleCondition==1, designNvsWHR$sampleCondition, NA)

designNvsWHR <- designNvsWHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHR$TCGA_white.LumB <- ifelse (designNvsWHR$sampleCondition==0, 1, 0)
designNvsWHR$Nigerian.LumB <- ifelse (designNvsWHR$sampleCondition==1, 1, 0)

designNvsWHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHR$TCGA_white.LumB+designNvsWHR$Nigerian.LumB)

quantids <- rownames(designNvsWHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13082    20
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsWHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.LumB-Nigerian.LumB, levels=colnames(designNvsWHR))

fit <- lmFit(v, designNvsWHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.LumB - Nigerian.LumB
Down                               988
NotSig                           10950
Up                                1136
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between LumB breast cancers in Nigerian and TCGA white patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between LumB \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,20)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between LumB \nbreast cancers in Nigerian and TCGA white breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_white-Nigerian-LumB-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA Black - LumB

designNvsBHR <- design
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="TCGA_black.LumB", 0, as.character(designNvsBHR$sampleCondition))
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="Nigerian.LumB", 1, as.character(designNvsBHR$sampleCondition))

designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition==0 | designNvsBHR$sampleCondition==1, designNvsBHR$sampleCondition, NA)

designNvsBHR <- designNvsBHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsBHR$TCGA_black.LumB <- ifelse (designNvsBHR$sampleCondition==0, 1, 0)
designNvsBHR$Nigerian.LumB <- ifelse (designNvsBHR$sampleCondition==1, 1, 0)

designNvsBHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsBHR$TCGA_black.LumB+designNvsBHR$Nigerian.LumB)

quantids <- rownames(designNvsBHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 12993    15
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]

v=voom(d,designNvsBHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_black.LumB-Nigerian.LumB, levels=colnames(designNvsBHR))

fit <- lmFit(v, designNvsBHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_black.LumB - Nigerian.LumB
Down                                99
NotSig                           12764
Up                                 122
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between LumB breast cancers in Nigerian and TCGA black patients\n quantile corrected")

qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between LumB \nbreast cancers in Nigerian and TCGA black breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,20)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
fit$genes$status <- ifelse(fit$F.p.value<0.05,"red","black")
limma::plotMA(fit, xlab = "Average log-expression",
       ylab = "Expression log-ratio (this sample vs others)", status=fit$genes$status, 
       main = "MA Plot of differential gene expression between LumB \nbreast cancers in Nigerian and TCGA black breast cancer patients")

write.csv(df_limmaprint, file = "TCGA_black-Nigerian-LumB-woribosomes.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

designNvsWHR <- design
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="TCGA_white.LumB", 0, as.character(designNvsWHR$sampleCondition))
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="Nigerian.LumB", 1, as.character(designNvsWHR$sampleCondition))

designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition==0 | designNvsWHR$sampleCondition==1, designNvsWHR$sampleCondition, NA)

designNvsWHR <- designNvsWHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHR$TCGA_white.LumB <- ifelse (designNvsWHR$sampleCondition==0, 1, 0)
designNvsWHR$Nigerian.LumB <- ifelse (designNvsWHR$sampleCondition==1, 1, 0)

designNvsWHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHR$TCGA_white.LumB+designNvsWHR$Nigerian.LumB)

quantids <- rownames(designNvsWHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13082    20
drop2 <- which(d$genes$symbol=="RPS25")
d <- d[-drop2,]
drop3 <- which(d$genes$symbol=="RPL18A")
d <- d[-drop3,]
drop4 <- which(d$genes$symbol=="RPL7")
d <- d[-drop4,]
drop5 <- which(d$genes$symbol=="RPL21")
d <- d[-drop5,]
drop6 <- which(d$genes$symbol=="RPS3A")
d <- d[-drop6,]
drop7 <- which(d$genes$symbol=="RPL39")
d <- d[-drop7,]
drop8 <- which(d$genes$symbol=="RPL7A")
d <- d[-drop8,]
drop9 <- which(d$genes$symbol=="RPL10")
d <- d[-drop9,]


v=voom(d,designNvsWHR,plot=T, normalize="quantile")

contr.matrix <- makeContrasts(TCGA_white.LumB-Nigerian.LumB, levels=colnames(designNvsWHR))

fit <- lmFit(v, designNvsWHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.LumB - Nigerian.LumB
Down                               988
NotSig                           10950
Up                                1136
df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = p.adjust(fit$p.value[,1], method='fdr'),
                       anno = fit$genes)

pathway.Nigerian.TCGAwhite.LumB <- as.data.frame(df_limma)

pathway.Nigerian.TCGAwhite.LumB$foldChange <- NA
row.pos <- which(! is.na(pathway.Nigerian.TCGAwhite.LumB$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.LumB$log2FoldChange >= 0)
row.neg <- which(! is.na(pathway.Nigerian.TCGAwhite.LumB$log2FoldChange) & 
                pathway.Nigerian.TCGAwhite.LumB$log2FoldChange < 0)
pathway.Nigerian.TCGAwhite.LumB$foldChange[row.pos] <- 2^pathway.Nigerian.TCGAwhite.LumB$log2FoldChange[row.pos]
pathway.Nigerian.TCGAwhite.LumB$foldChange[row.neg] <- -2^((-1) * pathway.Nigerian.TCGAwhite.LumB$log2FoldChange[row.neg])

pathway.Nigerian.TCGAwhite.LumB$log2FoldChange <- NULL
pathway.Nigerian.TCGAwhite.LumB$ENSEMBL <- pathway.Nigerian.TCGAwhite.LumB$anno$GeneID
pathway.Nigerian.TCGAwhite.LumB$SYMBOL <- pathway.Nigerian.TCGAwhite.LumB$anno$symbol

pathway.Nigerian.TCGAwhite.LumB$anno$GeneID <- NULL
pathway.Nigerian.TCGAwhite.LumB$anno$symbol <- NULL

pathway.Nigerian.TCGAwhite.LumB.flt <- pathway.Nigerian.TCGAwhite.LumB %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

genes.all <- pathway.Nigerian.TCGAwhite.LumB
genes.sig <- pathway.Nigerian.TCGAwhite.LumB.flt 

genes.all$ENSEMBL <- gsub('[.]\\d+', '', genes.all$ENSEMBL, perl = TRUE)
genes.sig$ENSEMBL <- gsub('[.]\\d+', '', genes.sig$ENSEMBL, perl = TRUE)

genes.all.anno <- bitr(geneID   =  genes.all$ENSEMBL, 
                      fromType = 'GENEID', 
                      toType   = c('ENTREZID', 'SYMBOL'), 
                      OrgDb    = 'EnsDb.Hsapiens.v75', 
                      drop     = TRUE)

genes.all.anno <- genes.all.anno[which(!duplicated(genes.all.anno$ENTREZID)), ]
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.all.anno$ENSEMBL <- genes.all.anno$GENEID
genes.all.anno$GENEID <- NULL

genes.all.anno <- merge(genes.all.anno, genes.all, by = 'ENSEMBL')
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.sig.anno <- genes.all.anno[genes.all.anno$ENSEMBL %in% 
                                genes.sig$ENSEMBL,]

gene.list <- genes.all.anno$foldChange
names(gene.list) <- genes.all.anno$ENTREZID
gene.list <- sort(gene.list, decreasing = TRUE)

ego <- enrichGO(gene          = genes.sig.anno$ENTREZID,
                universe      = as.character(genes.all.anno$ENTREZID),
                OrgDb         = 'org.Hs.eg.db',
                ont           = "BP",
                pAdjustMethod = "fdr",
                pvalueCutoff  = 0.05,
                readable      = TRUE)

as.data.frame(ego)
save(ego, file="GO-Nigerian-TCGAwhite-LumB.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.RData")
write.csv(ego, file="GO-Nigerian-TCGAwhite-LumB.significantgenes.fdr0.05.fc1.5.enrichGO.woribosomes.csv")

options(jupyter.plot_mimetypes = "image/svg+xml") 
options(repr.plot.width = 10, repr.plot.height = 5)

egokegg <- ego
for(i in 1:5) { 
  egokegg <- dropGO(egokegg, level = i)
}

p1 <- barplot(egokegg)
p2 <- dotplot(egokegg)

plot(p1)

plot(p2)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.


sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  stats4    grid      stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
 [1] AnnotationHub_2.16.1        BiocFileCache_1.8.0        
 [3] dbplyr_1.4.2                Glimma_1.12.0              
 [5] RColorBrewer_1.1-2          preprocessCore_1.46.0      
 [7] ashr_2.2-32                 ggfortify_0.4.7            
 [9] calibrate_1.7.2             MASS_7.3-51.4              
[11] sva_3.32.1                  mgcv_1.8-28                
[13] nlme_3.1-140                EnsDb.Hsapiens.v75_2.99.0  
[15] ensembldb_2.8.0             AnnotationFilter_1.8.0     
[17] GenomicFeatures_1.36.4      hexbin_1.27.3              
[19] stringi_1.4.3               dplyr_0.8.3                
[21] affy_1.62.0                 checkmate_1.9.3            
[23] pathview_1.24.0             org.Hs.eg.db_3.8.2         
[25] AnnotationDbi_1.46.0        clusterProfiler_3.12.0     
[27] pheatmap_1.0.12             genefilter_1.66.0          
[29] vsn_3.52.0                  RUVSeq_1.18.0              
[31] EDASeq_2.18.0               ShortRead_1.42.0           
[33] GenomicAlignments_1.20.0    Rsamtools_2.0.0            
[35] Biostrings_2.52.0           XVector_0.24.0             
[37] DESeq2_1.24.0               SummarizedExperiment_1.14.0
[39] DelayedArray_0.10.0         BiocParallel_1.18.0        
[41] matrixStats_0.54.0          Biobase_2.44.0             
[43] GenomicRanges_1.36.0        GenomeInfoDb_1.20.0        
[45] IRanges_2.18.1              S4Vectors_0.22.0           
[47] BiocGenerics_0.30.0         edgeR_3.26.4               
[49] limma_3.40.2                ggbiplot_0.55              
[51] scales_1.0.0                plyr_1.8.4                 
[53] ggplot2_3.2.1               gplots_3.0.1.1             

loaded via a namespace (and not attached):
  [1] rappdirs_0.3.1                rtracklayer_1.44.0           
  [3] R.methodsS3_1.7.1             tidyr_1.0.0                  
  [5] acepack_1.4.1                 bit64_0.9-7                  
  [7] knitr_1.23                    aroma.light_3.14.0           
  [9] R.utils_2.8.0                 data.table_1.12.2            
 [11] rpart_4.1-15                  hwriter_1.3.2                
 [13] KEGGREST_1.24.0               RCurl_1.95-4.12              
 [15] doParallel_1.0.14             cowplot_0.9.4                
 [17] RSQLite_2.1.1                 europepmc_0.3                
 [19] bit_1.1-14                    enrichplot_1.4.0             
 [21] xml2_1.2.2                    httpuv_1.5.2                 
 [23] assertthat_0.2.1              viridis_0.5.1                
 [25] xfun_0.7                      hms_0.5.2                    
 [27] evaluate_0.14                 promises_1.0.1               
 [29] progress_1.2.2                caTools_1.17.1.2             
 [31] Rgraphviz_2.28.0              igraph_1.2.4.1               
 [33] DBI_1.0.0                     geneplotter_1.62.0           
 [35] htmlwidgets_1.3               purrr_0.3.3                  
 [37] backports_1.1.4               annotate_1.62.0              
 [39] biomaRt_2.40.0                vctrs_0.2.0                  
 [41] withr_2.1.2                   ggforce_0.2.2                
 [43] triebeard_0.3.0               prettyunits_1.0.2            
 [45] cluster_2.0.9                 DOSE_3.10.1                  
 [47] lazyeval_0.2.2                crayon_1.3.4                 
 [49] pkgconfig_2.0.2               labeling_0.3                 
 [51] tweenr_1.0.1                  ProtGenerics_1.16.0          
 [53] nnet_7.3-12                   rlang_0.4.2                  
 [55] lifecycle_0.1.0               affyio_1.54.0                
 [57] rprojroot_1.3-2               polyclip_1.10-0              
 [59] graph_1.62.0                  Matrix_1.2-17                
 [61] urltools_1.7.3                base64enc_0.1-3              
 [63] ggridges_0.5.1                png_0.1-7                    
 [65] viridisLite_0.3.0             bitops_1.0-6                 
 [67] R.oo_1.22.0                   KernSmooth_2.23-15           
 [69] blob_1.1.1                    workflowr_1.4.0              
 [71] mixsqp_0.1-97                 stringr_1.4.0                
 [73] SQUAREM_2017.10-1             qvalue_2.16.0                
 [75] gridGraphics_0.4-1            memoise_1.1.0                
 [77] magrittr_1.5                  gdata_2.18.0                 
 [79] zlibbioc_1.30.0               compiler_3.6.0               
 [81] KEGGgraph_1.44.0              htmlTable_1.13.1             
 [83] Formula_1.2-3                 tidyselect_0.2.5             
 [85] highr_0.8                     yaml_2.2.0                   
 [87] GOSemSim_2.10.0               locfit_1.5-9.1               
 [89] latticeExtra_0.6-28           ggrepel_0.8.1                
 [91] fastmatch_1.1-0               tools_3.6.0                  
 [93] rstudioapi_0.10               foreach_1.4.4                
 [95] foreign_0.8-71                git2r_0.25.2                 
 [97] gridExtra_2.3                 farver_1.1.0                 
 [99] ggraph_1.0.2                  digest_0.6.19                
[101] rvcheck_0.1.3                 BiocManager_1.30.4           
[103] shiny_1.3.2                   Rcpp_1.0.1                   
[105] pscl_1.5.2                    later_0.8.0                  
[107] httr_1.4.1                    colorspace_1.4-1             
[109] XML_3.98-1.20                 fs_1.3.1                     
[111] truncnorm_1.0-8               splines_3.6.0                
[113] ggplotify_0.0.3               xtable_1.8-4                 
[115] jsonlite_1.6                  UpSetR_1.4.0                 
[117] zeallot_0.1.0                 R6_2.4.0                     
[119] Hmisc_4.2-0                   pillar_1.4.2                 
[121] htmltools_0.3.6               mime_0.7                     
[123] glue_1.3.1                    DESeq_1.36.0                 
[125] interactiveDisplayBase_1.22.0 codetools_0.2-16             
[127] fgsea_1.10.0                  lattice_0.20-38              
[129] tibble_2.1.3                  curl_3.3                     
[131] gtools_3.8.1                  GO.db_3.8.2                  
[133] survival_2.44-1.1             rmarkdown_1.13               
[135] munsell_0.5.0                 DO.db_2.9                    
[137] GenomeInfoDbData_1.2.1        iterators_1.0.10             
[139] reshape2_1.4.3                gtable_0.3.0